package keye.document_manage.dao.sqlite;

import java.util.HashMap;
import java.util.List;

import keye.document_manage.entity.Page;
import keye.document_manage.entity.TableFiled;
import keye.document_manage.util.SqlProviderSqlite;

import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.UpdateProvider;
import org.springframework.stereotype.Repository;

@Repository("sqliteBaseDao")
public interface BaseDaoSqlite<T> {

	@Select("select * from ${tableName}")
	List<HashMap<String, Object>> selectList(@Param("tableName") String tableName);
	
	@Select("select * from ${tableName}")
	List<HashMap<String, Object>> selectListByPage(@Param("tableName") String tableName, @Param("page")Page page);
	
	@InsertProvider(type=SqlProviderSqlite.class, method = "insert")
	int insert(@Param("tableName")String tableName, @Param("values")String values);
	
	/**
	 * 
	 * @param tableName
	 * @param values key为字段名，value为其值
	 * @return
	 */
//	@InsertProvider(type=SqlProviderSqlite.class, method = "insertBatch")
//	int insertBatch(@Param("tableName")String tableName,@Param("values")List<TableFiledValue> values);
	
	@UpdateProvider(type=SqlProviderSqlite.class, method = "dropTable")
	int dropeTable(@Param("tableName")String tableName);
	
	@UpdateProvider(type=SqlProviderSqlite.class, method = "createTable")
	int createTable(@Param("tableName")String tableName, @Param("fileds")List<TableFiled> fileds);
	
	@Select("SELECT count(*) FROM sqlite_master WHERE type='table' AND name=#{tableName, jdbcType=VARCHAR}")
	int isExistsTable(@Param("tableName")String tableName);
	
	
}
